{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  month  avg_high  avg_low  record_high  record_low  avg_precipitation\n",
      "0   Jan        58       42           74          22              2.950\n",
      "1   Feb        61       45           78          26              3.021\n",
      "   month  avg_high  avg_low  record_high  record_low  avg_precipitation\n",
      "9    oct        73       54           96          34               0.81\n",
      "10   Nov        64       48           84          30               1.70\n",
      "11   Dec        58       42           73          21               2.56\n"
     ]
    }
   ],
   "source": [
    "df = pd.DataFrame([['Jan',58,42,74,22,2.95],\n",
    "            ['Feb', 61,45,78,26,3.021],\n",
    "            ['Mar', 65,48,84,25,2.34],\n",
    "            ['Apr', 67,50,92,28,1.02],\n",
    "            ['May', 71,53,98,35,0.481],\n",
    "            ['Jun', 75,56,107,41,0.11],\n",
    "            ['Jul', 77,58,105,44,0.01],\n",
    "            ['Aug', 77,59,102,43,0.03],\n",
    "            ['sep', 77,57,103,40,0.17],\n",
    "            ['oct', 73,54,96,34,0.81],\n",
    "            ['Nov', 64,48,84,30,1.7],\n",
    "            ['Dec', 58,42,73,21,2.56]],\n",
    "          index=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],\n",
    "          columns=['month', 'avg_high', 'avg_low', 'record_high', 'record_low', 'avg_precipitation'])\n",
    "print(df.head(2))\n",
    "print(df.tail(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "month                 object\n",
       "avg_high               int64\n",
       "avg_low                int64\n",
       "record_high            int64\n",
       "record_low             int64\n",
       "avg_precipitation    float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Int64Index([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], dtype='int64')"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['month', 'avg_high', 'avg_low', 'record_high', 'record_low',\n",
       "       'avg_precipitation'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['Jan', 58, 42, 74, 22, 2.95],\n",
       "       ['Feb', 61, 45, 78, 26, 3.021],\n",
       "       ['Mar', 65, 48, 84, 25, 2.34],\n",
       "       ['Apr', 67, 50, 92, 28, 1.02],\n",
       "       ['May', 71, 53, 98, 35, 0.481],\n",
       "       ['Jun', 75, 56, 107, 41, 0.11],\n",
       "       ['Jul', 77, 58, 105, 44, 0.01],\n",
       "       ['Aug', 77, 59, 102, 43, 0.03],\n",
       "       ['sep', 77, 57, 103, 40, 0.17],\n",
       "       ['oct', 73, 54, 96, 34, 0.81],\n",
       "       ['Nov', 64, 48, 84, 30, 1.7],\n",
       "       ['Dec', 58, 42, 73, 21, 2.56]], dtype=object)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>avg_high</th>\n",
       "      <th>avg_low</th>\n",
       "      <th>record_high</th>\n",
       "      <th>record_low</th>\n",
       "      <th>avg_precipitation</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>12.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>12.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>68.583333</td>\n",
       "      <td>51.000000</td>\n",
       "      <td>91.333333</td>\n",
       "      <td>32.416667</td>\n",
       "      <td>1.266833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>7.366488</td>\n",
       "      <td>6.060303</td>\n",
       "      <td>12.323911</td>\n",
       "      <td>8.240238</td>\n",
       "      <td>1.185503</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>58.000000</td>\n",
       "      <td>42.000000</td>\n",
       "      <td>73.000000</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>0.010000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>63.250000</td>\n",
       "      <td>47.250000</td>\n",
       "      <td>82.500000</td>\n",
       "      <td>25.750000</td>\n",
       "      <td>0.155000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>69.000000</td>\n",
       "      <td>51.500000</td>\n",
       "      <td>94.000000</td>\n",
       "      <td>32.000000</td>\n",
       "      <td>0.915000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>75.500000</td>\n",
       "      <td>56.250000</td>\n",
       "      <td>102.250000</td>\n",
       "      <td>40.250000</td>\n",
       "      <td>2.395000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>77.000000</td>\n",
       "      <td>59.000000</td>\n",
       "      <td>107.000000</td>\n",
       "      <td>44.000000</td>\n",
       "      <td>3.021000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        avg_high    avg_low  record_high  record_low  avg_precipitation\n",
       "count  12.000000  12.000000    12.000000   12.000000          12.000000\n",
       "mean   68.583333  51.000000    91.333333   32.416667           1.266833\n",
       "std     7.366488   6.060303    12.323911    8.240238           1.185503\n",
       "min    58.000000  42.000000    73.000000   21.000000           0.010000\n",
       "25%    63.250000  47.250000    82.500000   25.750000           0.155000\n",
       "50%    69.000000  51.500000    94.000000   32.000000           0.915000\n",
       "75%    75.500000  56.250000   102.250000   40.250000           2.395000\n",
       "max    77.000000  59.000000   107.000000   44.000000           3.021000"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>avg_high</th>\n",
       "      <th>avg_low</th>\n",
       "      <th>record_high</th>\n",
       "      <th>record_low</th>\n",
       "      <th>avg_precipitation</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Jun</td>\n",
       "      <td>75</td>\n",
       "      <td>56</td>\n",
       "      <td>107</td>\n",
       "      <td>41</td>\n",
       "      <td>0.110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Jul</td>\n",
       "      <td>77</td>\n",
       "      <td>58</td>\n",
       "      <td>105</td>\n",
       "      <td>44</td>\n",
       "      <td>0.010</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>sep</td>\n",
       "      <td>77</td>\n",
       "      <td>57</td>\n",
       "      <td>103</td>\n",
       "      <td>40</td>\n",
       "      <td>0.170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Aug</td>\n",
       "      <td>77</td>\n",
       "      <td>59</td>\n",
       "      <td>102</td>\n",
       "      <td>43</td>\n",
       "      <td>0.030</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>May</td>\n",
       "      <td>71</td>\n",
       "      <td>53</td>\n",
       "      <td>98</td>\n",
       "      <td>35</td>\n",
       "      <td>0.481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>oct</td>\n",
       "      <td>73</td>\n",
       "      <td>54</td>\n",
       "      <td>96</td>\n",
       "      <td>34</td>\n",
       "      <td>0.810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apr</td>\n",
       "      <td>67</td>\n",
       "      <td>50</td>\n",
       "      <td>92</td>\n",
       "      <td>28</td>\n",
       "      <td>1.020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mar</td>\n",
       "      <td>65</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "      <td>25</td>\n",
       "      <td>2.340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Nov</td>\n",
       "      <td>64</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "      <td>30</td>\n",
       "      <td>1.700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Feb</td>\n",
       "      <td>61</td>\n",
       "      <td>45</td>\n",
       "      <td>78</td>\n",
       "      <td>26</td>\n",
       "      <td>3.021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Jan</td>\n",
       "      <td>58</td>\n",
       "      <td>42</td>\n",
       "      <td>74</td>\n",
       "      <td>22</td>\n",
       "      <td>2.950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Dec</td>\n",
       "      <td>58</td>\n",
       "      <td>42</td>\n",
       "      <td>73</td>\n",
       "      <td>21</td>\n",
       "      <td>2.560</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   month  avg_high  avg_low  record_high  record_low  avg_precipitation\n",
       "5    Jun        75       56          107          41              0.110\n",
       "6    Jul        77       58          105          44              0.010\n",
       "8    sep        77       57          103          40              0.170\n",
       "7    Aug        77       59          102          43              0.030\n",
       "4    May        71       53           98          35              0.481\n",
       "9    oct        73       54           96          34              0.810\n",
       "3    Apr        67       50           92          28              1.020\n",
       "2    Mar        65       48           84          25              2.340\n",
       "10   Nov        64       48           84          30              1.700\n",
       "1    Feb        61       45           78          26              3.021\n",
       "0    Jan        58       42           74          22              2.950\n",
       "11   Dec        58       42           73          21              2.560"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_values('record_high', ascending=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     42\n",
       "1     45\n",
       "2     48\n",
       "3     50\n",
       "4     53\n",
       "5     56\n",
       "6     58\n",
       "7     59\n",
       "8     57\n",
       "9     54\n",
       "10    48\n",
       "11    42\n",
       "Name: avg_low, dtype: int64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.avg_low"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     42\n",
       "1     45\n",
       "2     48\n",
       "3     50\n",
       "4     53\n",
       "5     56\n",
       "6     58\n",
       "7     59\n",
       "8     57\n",
       "9     54\n",
       "10    48\n",
       "11    42\n",
       "Name: avg_low, dtype: int64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['avg_low']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>avg_high</th>\n",
       "      <th>avg_low</th>\n",
       "      <th>record_high</th>\n",
       "      <th>record_low</th>\n",
       "      <th>avg_precipitation</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mar</td>\n",
       "      <td>65</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "      <td>25</td>\n",
       "      <td>2.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apr</td>\n",
       "      <td>67</td>\n",
       "      <td>50</td>\n",
       "      <td>92</td>\n",
       "      <td>28</td>\n",
       "      <td>1.02</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  month  avg_high  avg_low  record_high  record_low  avg_precipitation\n",
       "2   Mar        65       48           84          25               2.34\n",
       "3   Apr        67       50           92          28               1.02"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>avg_low</th>\n",
       "      <th>avg_high</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>42</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>45</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>48</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>50</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>53</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>56</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>58</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>59</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>57</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>54</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>48</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>42</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    avg_low  avg_high\n",
       "0        42        58\n",
       "1        45        61\n",
       "2        48        65\n",
       "3        50        67\n",
       "4        53        71\n",
       "5        56        75\n",
       "6        58        77\n",
       "7        59        77\n",
       "8        57        77\n",
       "9        54        73\n",
       "10       48        64\n",
       "11       42        58"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['avg_low', 'avg_high']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>avg_low</th>\n",
       "      <th>avg_high</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>42</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>45</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>48</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>50</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>53</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>56</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>58</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>59</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>57</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>54</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>48</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>42</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    avg_low  avg_high\n",
       "0        42        58\n",
       "1        45        61\n",
       "2        48        65\n",
       "3        50        67\n",
       "4        53        71\n",
       "5        56        75\n",
       "6        58        77\n",
       "7        59        77\n",
       "8        57        77\n",
       "9        54        73\n",
       "10       48        64\n",
       "11       42        58"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:,['avg_low', 'avg_high']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "avg_precipitation    0.81\n",
       "Name: 9, dtype: object"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[9,['avg_precipitation']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>record_high</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apr</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>May</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  month  record_high\n",
       "3   Apr           92\n",
       "4   May           98"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[3:5, [0,3]] # 3-5行,0和 3列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 8.filtering"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>avg_high</th>\n",
       "      <th>avg_low</th>\n",
       "      <th>record_high</th>\n",
       "      <th>record_low</th>\n",
       "      <th>avg_precipitation</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Jan</td>\n",
       "      <td>58</td>\n",
       "      <td>42</td>\n",
       "      <td>74</td>\n",
       "      <td>22</td>\n",
       "      <td>2.950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Feb</td>\n",
       "      <td>61</td>\n",
       "      <td>45</td>\n",
       "      <td>78</td>\n",
       "      <td>26</td>\n",
       "      <td>3.021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mar</td>\n",
       "      <td>65</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "      <td>25</td>\n",
       "      <td>2.340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apr</td>\n",
       "      <td>67</td>\n",
       "      <td>50</td>\n",
       "      <td>92</td>\n",
       "      <td>28</td>\n",
       "      <td>1.020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Nov</td>\n",
       "      <td>64</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "      <td>30</td>\n",
       "      <td>1.700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Dec</td>\n",
       "      <td>58</td>\n",
       "      <td>42</td>\n",
       "      <td>73</td>\n",
       "      <td>21</td>\n",
       "      <td>2.560</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   month  avg_high  avg_low  record_high  record_low  avg_precipitation\n",
       "0    Jan        58       42           74          22              2.950\n",
       "1    Feb        61       45           78          26              3.021\n",
       "2    Mar        65       48           84          25              2.340\n",
       "3    Apr        67       50           92          28              1.020\n",
       "10   Nov        64       48           84          30              1.700\n",
       "11   Dec        58       42           73          21              2.560"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df.avg_precipitation > 1.0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>avg_high</th>\n",
       "      <th>avg_low</th>\n",
       "      <th>record_high</th>\n",
       "      <th>record_low</th>\n",
       "      <th>avg_precipitation</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Jun</td>\n",
       "      <td>75</td>\n",
       "      <td>56</td>\n",
       "      <td>107</td>\n",
       "      <td>41</td>\n",
       "      <td>0.11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Jul</td>\n",
       "      <td>77</td>\n",
       "      <td>58</td>\n",
       "      <td>105</td>\n",
       "      <td>44</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Aug</td>\n",
       "      <td>77</td>\n",
       "      <td>59</td>\n",
       "      <td>102</td>\n",
       "      <td>43</td>\n",
       "      <td>0.03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  month  avg_high  avg_low  record_high  record_low  avg_precipitation\n",
       "5   Jun        75       56          107          41               0.11\n",
       "6   Jul        77       58          105          44               0.01\n",
       "7   Aug        77       59          102          43               0.03"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df['month'].isin(['Jun','Jul','Aug'])]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 9.aassignment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   month  avg_high  avg_low  record_high  record_low  avg_precipitation\n",
      "9    oct        73       54           96          34              101.3\n",
      "10   Nov        64       48           84          30                1.7\n"
     ]
    }
   ],
   "source": [
    "df.loc[9, ['avg_precipitation']] = 101.3\n",
    "print(df.iloc[9:11])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  month  avg_high  avg_low  record_high  record_low  avg_precipitation\n",
      "0   Jan        58       42           74          22              2.950\n",
      "1   Feb        61       45           78          26              3.021\n",
      "2   Mar        65       48           84          25              2.340\n",
      "3   Apr        67       50           92          28              1.020\n",
      "4   May        71       53           98          35              0.481\n"
     ]
    }
   ],
   "source": [
    "df.loc[9,['avg_precipitation']] = np.nan\n",
    "print(df.head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  month  avg_high  avg_low  record_high  record_low  avg_precipitation  \\\n",
      "0   Jan        58       42           74          22              2.950   \n",
      "1   Feb        61       45           78          26              3.021   \n",
      "2   Mar        65       48           84          25              2.340   \n",
      "3   Apr        67       50           92          28              1.020   \n",
      "4   May        71       53           98          35              0.481   \n",
      "\n",
      "   avg_day  \n",
      "0     50.0  \n",
      "1     53.0  \n",
      "2     56.5  \n",
      "3     58.5  \n",
      "4     62.0  \n"
     ]
    }
   ],
   "source": [
    "df['avg_day'] = (df.avg_low + df.avg_high) / 2\n",
    "print(df.head())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 10.renaming columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>avg_high</th>\n",
       "      <th>avg_low</th>\n",
       "      <th>record_high</th>\n",
       "      <th>record_low</th>\n",
       "      <th>avg_rain</th>\n",
       "      <th>avg_day</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Jan</td>\n",
       "      <td>58</td>\n",
       "      <td>42</td>\n",
       "      <td>74</td>\n",
       "      <td>22</td>\n",
       "      <td>2.950</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Feb</td>\n",
       "      <td>61</td>\n",
       "      <td>45</td>\n",
       "      <td>78</td>\n",
       "      <td>26</td>\n",
       "      <td>3.021</td>\n",
       "      <td>53.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mar</td>\n",
       "      <td>65</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "      <td>25</td>\n",
       "      <td>2.340</td>\n",
       "      <td>56.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apr</td>\n",
       "      <td>67</td>\n",
       "      <td>50</td>\n",
       "      <td>92</td>\n",
       "      <td>28</td>\n",
       "      <td>1.020</td>\n",
       "      <td>58.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>May</td>\n",
       "      <td>71</td>\n",
       "      <td>53</td>\n",
       "      <td>98</td>\n",
       "      <td>35</td>\n",
       "      <td>0.481</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Jun</td>\n",
       "      <td>75</td>\n",
       "      <td>56</td>\n",
       "      <td>107</td>\n",
       "      <td>41</td>\n",
       "      <td>0.110</td>\n",
       "      <td>65.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Jul</td>\n",
       "      <td>77</td>\n",
       "      <td>58</td>\n",
       "      <td>105</td>\n",
       "      <td>44</td>\n",
       "      <td>0.010</td>\n",
       "      <td>67.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Aug</td>\n",
       "      <td>77</td>\n",
       "      <td>59</td>\n",
       "      <td>102</td>\n",
       "      <td>43</td>\n",
       "      <td>0.030</td>\n",
       "      <td>68.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>sep</td>\n",
       "      <td>77</td>\n",
       "      <td>57</td>\n",
       "      <td>103</td>\n",
       "      <td>40</td>\n",
       "      <td>0.170</td>\n",
       "      <td>67.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>oct</td>\n",
       "      <td>73</td>\n",
       "      <td>54</td>\n",
       "      <td>96</td>\n",
       "      <td>34</td>\n",
       "      <td>NaN</td>\n",
       "      <td>63.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Nov</td>\n",
       "      <td>64</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "      <td>30</td>\n",
       "      <td>1.700</td>\n",
       "      <td>56.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Dec</td>\n",
       "      <td>58</td>\n",
       "      <td>42</td>\n",
       "      <td>73</td>\n",
       "      <td>21</td>\n",
       "      <td>2.560</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   month  avg_high  avg_low  record_high  record_low  avg_rain  avg_day\n",
       "0    Jan        58       42           74          22     2.950     50.0\n",
       "1    Feb        61       45           78          26     3.021     53.0\n",
       "2    Mar        65       48           84          25     2.340     56.5\n",
       "3    Apr        67       50           92          28     1.020     58.5\n",
       "4    May        71       53           98          35     0.481     62.0\n",
       "5    Jun        75       56          107          41     0.110     65.5\n",
       "6    Jul        77       58          105          44     0.010     67.5\n",
       "7    Aug        77       59          102          43     0.030     68.0\n",
       "8    sep        77       57          103          40     0.170     67.0\n",
       "9    oct        73       54           96          34       NaN     63.5\n",
       "10   Nov        64       48           84          30     1.700     56.0\n",
       "11   Dec        58       42           73          21     2.560     50.0"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.rename(columns = {'avg_precipitation':'avg_rain'}, inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>av_hi</th>\n",
       "      <th>av_lo</th>\n",
       "      <th>rec_hi</th>\n",
       "      <th>rec_lo</th>\n",
       "      <th>av_rain</th>\n",
       "      <th>yyy</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Jan</td>\n",
       "      <td>58</td>\n",
       "      <td>42</td>\n",
       "      <td>74</td>\n",
       "      <td>22</td>\n",
       "      <td>2.950</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Feb</td>\n",
       "      <td>61</td>\n",
       "      <td>45</td>\n",
       "      <td>78</td>\n",
       "      <td>26</td>\n",
       "      <td>3.021</td>\n",
       "      <td>53.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Mar</td>\n",
       "      <td>65</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "      <td>25</td>\n",
       "      <td>2.340</td>\n",
       "      <td>56.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apr</td>\n",
       "      <td>67</td>\n",
       "      <td>50</td>\n",
       "      <td>92</td>\n",
       "      <td>28</td>\n",
       "      <td>1.020</td>\n",
       "      <td>58.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>May</td>\n",
       "      <td>71</td>\n",
       "      <td>53</td>\n",
       "      <td>98</td>\n",
       "      <td>35</td>\n",
       "      <td>0.481</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  month  av_hi  av_lo  rec_hi  rec_lo  av_rain   yyy\n",
       "0   Jan     58     42      74      22    2.950  50.0\n",
       "1   Feb     61     45      78      26    3.021  53.0\n",
       "2   Mar     65     48      84      25    2.340  56.5\n",
       "3   Apr     67     50      92      28    1.020  58.5\n",
       "4   May     71     53      98      35    0.481  62.0"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns = ['month',  'av_hi', 'av_lo', 'rec_hi', 'rec_lo', 'av_rain', 'yyy']\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 11.iterate a df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 Jan 74\n",
      "1 Feb 78\n",
      "2 Mar 84\n",
      "3 Apr 92\n",
      "4 May 98\n",
      "5 Jun 107\n",
      "6 Jul 105\n",
      "7 Aug 102\n",
      "8 sep 103\n",
      "9 oct 96\n",
      "10 Nov 84\n",
      "11 Dec 73\n"
     ]
    }
   ],
   "source": [
    "for index, row in df.iterrows():\n",
    "    print(index, row['month'], row['rec_hi'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 12.wirte to csv file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('foo.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
